package com.pierrepochon.RemoTxt.util;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

import com.pierrepochon.RemoTxt.DAO.SMS;
import com.pierrepochon.RemoTxt.util.XML.ParserXMLHandler;

public class XMLSaxParserBuilder {
	
	@SuppressWarnings("finally")
	public static ParserXMLHandler BuildParser(String xmlStr)
	{
		SAXParserFactory fabrique;
		SAXParser parser;
		DefaultHandler handler = null;
		try {
			fabrique = SAXParserFactory.newInstance();
			parser = fabrique.newSAXParser();
			handler =  new ParserXMLHandler();
			InputStream in = new ByteArrayInputStream(xmlStr.getBytes());
									
			parser.parse(in,handler);
			
			
		} catch (ParserConfigurationException e) {
			Log.e("Erreur Parser","SAXCOnfExeption");
			e.printStackTrace();
		} catch (SAXException e) {
			Log.e("SAXExeption",e.getMessage());
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		finally
		{
			return (ParserXMLHandler) handler;
		}
		
	}

}
